#include "Arduino.h"
#include "Compass.h"
#include "Wire.h"

Compass::Compass(void) {
    _cADDR = 0x21;
    _cWRAM = 0x47;
    _cOPAD = 0x74;
    _cOCMD = 0x72;
}

void Compass::begin(void) {
  Wire.beginTransmission(_cADDR); // transmit to compass
  Wire.write(_cWRAM);              // 'G' write RAM command
  Wire.write(_cOPAD);              // 0x74 Operational register
  Wire.write(_cOCMD);              // 20 Hz, Periodic S/R on, Continuous Mode
  Wire.endTransmission();    // stop transmitting

}

int Compass::heading(void) {

  Wire.requestFrom(_cADDR, 2);
  
    
  byte MSB = Wire.read();
  int temp = ((int(MSB) << 8) + Wire.read());
  return temp;
}
